<template>
  <div>
    <Header />
    <div class="nav">
      <van-tabs v-model="active" @click="container">
        <van-tab
          v-for="item in column.navData"
          :key="item.id"
          :title="item.name"
        >
          <div class="box">
            <p class="name">{{ item.name }}</p>
            <p class="desc">{{ item.front_desc }}</p>
          </div>
        </van-tab>
      </van-tabs>
    </div>
    <div class="content">
      <router-link
        class="content-box"
        :to="{ path: '/detail', query: { id: item.id } }"
        v-for="item in goods.data"
        :key="item.id"
      >
        <img :src="item.list_pic_url" alt="" />
        <p class="text">{{ item.name }}</p>
        <p class="cash">￥{{ item.retail_price }}</p>
      </router-link>
    </div>
  </div>
</template>

<script>
import Header from "@/components/header/header.vue";
import { category, goods } from "@/api/category/categorylist/index.js";
export default {
  components: {
    Header,
  },
  data() {
    return {
      active: 0,
      column: {},
      goods: {},
    };
  },
  methods: {
    container(name, title) {
      let id = this.column.navData.filter((el) => el.name == title)[0].id;
      goods({ categoryId: id }).then((res) => {
        this.goods = res;
      });
    },
  },
  mounted() {
    let id = this.$route.query.id;
    category({ id: id }).then((res) => {
      this.column = res;
      this.active = res.navData.findIndex((item) => {
        return item.id == id;
      });
    });
    goods({ categoryId: id }).then((res) => {
      this.goods = res;
      console.log(this.goods);
    });
  },
};
</script>

<style lang="scss" scoped>
* {
  margin: 0;
  padding: 0;
}
html {
  background-color: #f4f4f4;
}
.nav {
  background-color: #f4f4f4;
  .box {
    margin-top: 10px;
    background-color: #fff;
    padding: 15px;
    width: 345px;
    height: 71px;
    text-align: center;
    margin-bottom: 3px;
    .name {
      color: #333;
      font-size: 16px;
      margin-top: 15px;
      margin-bottom: 10px;
    }
    .desc {
      color: #999;
      font-size: 12px;
    }
  }
}
.content {
  width: 375px;
  display: flex;
  justify-content: space-between;
  flex-wrap: wrap;
  background-color: #f4f4f4;
  .content-box {
    width: 186px;
    background-color: #fff;
    margin: 3px 0;
    img {
      width: 151px;
    }
    .text {
      margin-top: 7px;
      font-size: 12px;
      color: #000;
    }
    .cash {
      margin: 15px auto;
      font-size: 14px;
      color: #b4282d;
    }
  }
}
</style>